/*
 *说明：资源信息表 (APP)首页脚本
 *
 *@author liuxun 2013-05-06
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[
		          
		    {title:'节点名称',field:'node_decode',align:'center',width:50},
		    
		    {title:'资源组',field:'rsc_grp_name',align:'center',width:100},
		    
		    {title:'资源名称',field:'rsc_name',align:'center',width:150},

            {title:'管理IP',field:'manage_ip',align:'center',width:80},

            {title:'服务IP',field:'service_ip',align:'center',width:80},
            
            {title:'资源类型',field:'rsc_type_decode',align:'center',width:80},
            
            {title:'资源等级',field:'rsc_level_decode',align:'center',width:40},

            {title:'管理账号',field:'manage_acc',align:'center',width:80},
            
            {title:'应用URL',field:'http_url',align:'center',width:80},
            
            {title:'资源索引',field:'rsc_no',align:'center',width:60},

            {title:'资源状态',field:'rsc_status_decode',align:'center',width:60},

			{title:'资源帐号',field:'operation',align:'center',width:70,
	        	formatter:function(value,rec){
         		var s = '<a style="cursor:pointer; color:blue" onclick=\'showInfo("' + rec.key + '")\'>查看明细</a>';
	        	    return s;
		   		}
		    },
		    {title:'资源人员',field:'operation1',align:'center',width:70,
	        	formatter:function(value,rec){
         		var u = '<a style="cursor:pointer; color:blue" onclick=\'showInfoUsr("' + rec.key + '")\'>查看明细</a>';
	        	    return u;
		   		}
		    }
        ]],
		pagination:true,
		singleSelect: false
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#addBtn').click(addOperation);
	$('#editBtn').click(editOperation);
	$('#deleteBtn').click(deleteOperation);
	$('#copyBtn').click(copyOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'C_RSC!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//选择资源组
function select_c_rsc_grp() {
	var node_id = $('#node_id').val();
	var action = "C_RSC_GRP!showSelect.do?model.rsc_grp_status=01&model.node_id="+node_id;
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_grp_id').val(row.rsc_grp_id);
		$('#rsc_grp_name').val(row.rsc_grp_name);
	}
}

//查看明细  资源帐号
function showInfo(key) {
	var url = 'C_RSC!showAPPInfo.do?model.key=' + key;
	openWin(url,'pop','A3');
}

//查看明细  资源人员
function showInfoUsr(key) {
	var url = 'C_RSC!showInfoUsr.do?model.key=' + key;
	openWin(url,'pop','A3');
}

//添加资源信息表
function addOperation(){  
	var url = 'C_RSC!showAddAPP.do';
	openWin(url,'pop','A3');
}

//编辑资源信息表
function editOperation(){  
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}
	
	if (rows[0].rsc_status == '03') {
		showInfoWin('已删除的资源信息不允许修改操作！');
      	return; 
	}

	var url = 'C_RSC!showEditAPP.do?model.key=' + rows[0].key;
	openWin(url,'pop','A3');
}   

//删除资源信息表
function deleteOperation() {
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要删除的记录!');	
		return;
	}

	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}
	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要删除选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'C_RSC!doDelete.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//复制资源信息表
function copyOperation(){  
	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}

	var url = 'C_RSC!showCopyAPP.do?model.key=' + rows[0].key;
	openWin(url,'pop','A3');
}   


//操作成功后刷新列表
function afterOK(){
	queryOperation();
}